package Day10;

import javax.crypto.spec.PSource;

/**
 * @author HYHwtx
 * @version 1.0
 * @date 2022/2/16 11:10
 */
public class Demo10 {
    //数组拷贝，要求数组空间是独立的
    public static void main(String[] args) {
        //
        int[] arr1 = {10,20,30,40};
        //创建一个新数组arr2
        int[] arr2 = new int[arr1.length];
        //遍历arr1，将每一个元素拷贝到arr2当中
        for (int i = 0; i < arr1.length; i++) {
            arr2[i] = arr1[i];
        }
        //修改arr2.不会对arr1有影响
        arr2[0] = 100;
        System.out.println("arr1的元素");
        for (int i = 0; i < arr1.length; i++) {
            System.out.println(arr1[i]);
        }
        System.out.println("arr2的元素");
        for (int i = 0; i < arr2.length; i++) {
            System.out.println(arr2[i]);
        }
        System.out.println(arr1);
        System.out.println(arr2);
    }
}
